﻿using System;
using System.Collections.Generic;
using System.Text;
using JsonSharp;
using Barbar.MapReport.HtmlRender.Operations.Regions;
using JsonSharp.Collections;
using Barbar.MapReport.Common.Drawing;
using System.Drawing;
using Barbar.MapReport.HtmlRender.Handlers;

namespace Barbar.MapReport.HtmlRender {
  internal class BusinessRegionCallbackService : RegionCallbackService {
    internal override JsonValue ProcessCallback(MapCallbackData callbackData) {
      RegionsWithBusinessProcessingData value = (RegionsWithBusinessProcessingData)GetValue(callbackData);

      JsonObjects result = new JsonObjects();
      foreach (BusinessRegionList regionList in value.GetValidBusinessRegionLists(callbackData.GeoBound, callbackData.ZoomLevel)) {
        Color fillColor = value.LegendRangeList.GetColor(regionList.Value);

        PolygonBehavior behavior = null;
        if (value.RegionOptions != null)
          behavior = value.RegionOptions.PolygonBehavior;
        AppendPolygon(result, regionList, callbackData.ZoomLevel, behavior, Color.FromArgb(128, fillColor), value.StrokeColor.Color, value.StrokeWeight);
      }

      return result;
    }
  }
}
